package com.logistics.user;

import java.sql.*;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class LoginDao {
	public boolean validate(String username,String password){
		boolean ret = false;
		Connection conn=null;
		PreparedStatement stmt=null;
		ResultSet rs=null;
		try {
			Class.forName("oracle.jdbc.OracleDriver");
			String url="jdbc:oracle:thin:@10.25.92.41:1521:oracle";
			conn=DriverManager.getConnection(url,"scott","1316190");
			
			String sql="select * from users where username=? and password = ?";
			stmt=conn.prepareStatement(sql);
			stmt.setString(1, username);
			stmt.setString(2, password);
			rs=stmt.executeQuery();
			if(rs.next()){
				ret=true;
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally
		{
			try {
				if(rs!=null)
				rs.close();	
				if(stmt!=null)
				stmt.close();
				if(conn!=null)
				conn.close();			
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return ret;
	}

}
